#include <iostream>
#include <string.h>
#include "sha.h"
#include "secblock.h"
#include "modes.h"
#include "hex.h"
#pragma comment( lib, "cryptlib.lib")
using namespace std;
using namespace CryptoPP;
int main()
{
	string message1;
	string message2;
	cout << "please enter the message to encrypt: ";
	getline(cin, message1);
	SHA256 sha256;
	char* hashCode = new char[sha256.DigestSize()];
	sha256.CalculateDigest((byte*)hashCode, (const byte *)message1.c_str(), message1.size());
	static const char* const lut = "0123456789ABCDEF";
	size_t len = string(hashCode, sha256.DigestSize()).length();
	string hexHashCode;
	hexHashCode.reserve(2 * len);
	for (size_t i = 0; i < len; ++i)
	{
		const unsigned char c = string(hashCode, sha256.DigestSize())[i];
		hexHashCode.push_back(lut[c >> 4]);
		hexHashCode.push_back(lut[c & 15]);
	}
	cout << "The hash is " << hexHashCode << endl;
	cout<< "please enter the message to verify: ";
	getline(cin, message2);
	if (sha256.VerifyDigest((byte*)hashCode, (const byte *)message2.c_str(), message2.size()))
	{
		cout << "Success!\nThe orignal message is "<<message1<<'\n';
	}
	else
		cout << "Fail!";
	system("pause");
	return 0;
}